<!DOCTYPE html>
<html lang="en-US">
    <head>
        <title>Expect - automate interactions with command line programs that expose a text terminal interface. - metacpan.org</title>
        <link rel="preload" as="fetch" href="https://metacpan.org/account/login_status" crossorigin="anonymous" />
        <link href="https://metacpan.org/_assets/b8ccceeed47a0652049703d99326a9cea4933443.css" rel="stylesheet" type="text/css">
        <script src="https://metacpan.org/_assets/6bfedafe2d7caa915b7d84f61b45936818e3242e.js" type="text/javascript" defer></script>
        <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Expect - MetaCPAN" href="https://metacpan.org/dist/Expect/releases.rss" />
        <link rel="canonical" href="Expect.html" />
        <meta name="description" content="automate interactions with command line programs that expose a text terminal interface." />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
        <link rel="shortcut icon" href="https://metacpan.org/static/icons/favicon.ico">
        <link rel="apple-touch-icon" sizes="152x152" href="https://metacpan.org/static/icons/apple-touch-icon.png">
        <link rel="search" href="https://metacpan.org/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN">
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          (function(skey, ga_id){
            ga('create', ga_id, {
              siteSpeedSampleRate : 100,
              storage             : 'none',
              clientId            : localStorage.getItem(skey)
            });
            ga(function(tracker) {
              localStorage.setItem(skey, tracker.get('clientId'));
            });
            ga('send', 'pageview');
          })('ga:clientId', 'UA-27829474-1');
        </script>
<meta name="twitter:card"        content="summary" />
<meta name="twitter:url"         content="https://metacpan.org/pod/Expect" />
<meta name="twitter:title"       content="Expect" />
<meta name="twitter:description" content="automate interactions with command line programs that expose a text terminal interface." />
<meta name="twitter:site"        content="metacpan" />
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="header-logo-large hidden-xs">
              <a href="https://metacpan.org/" tabindex="0">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#logo" />
                </svg>
              </a>
            </div>
            <div class="header-logo-icon visible-xs">
              <a href="https://metacpan.org/">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#dots" />
                </svg>
              </a>
            </div>
            <ul class="nav navbar-nav menu-items hidden-xs hidden-sm">
              <li><a href="https://metacpan.org/about">About</a></li>
              <li><a href="https://metacpan.org/about/sponsors">Sponsor</a></li>
              <li><a href="https://grep.metacpan.org/">grep::cpan</a></li>
              <li><a href="https://metacpan.org/recent">Recent</a></li>
              <li><a href="https://metacpan.org/about/faq">FAQ</a></li>
              <li><a href="https://metacpan.org/tools">Tools</a></li>
              <li><a href="https://fastapi.metacpan.org/">API</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <button type="button" class="searchbar-btn visible-xs visible-sm">
                    <i class="fa fa-search button-fa-icon"></i>
                </button>
                <form action="https://metacpan.org/search" class="searchbar-form visible-md visible-lg search-form form-horizontal">
                   <input type="hidden" name="size" id="metacpan_search-size" value="20">
                  <div class="form-group">
                      <div class="search-group">
                        <i class="fa fa-search"></i>
                        <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value="">
                      </div>
                  </div>
                </form>
                    <li class="icon-slidepanel visible-xs visible-sm">
                      <button data-toggle="slidepanel" data-target=".slidepanel">
                        <span class="button-fa-icon">
                          <i class="fa fa-bars slidepanel-open"></i>
                          <i class="fa fa-times slidepanel-close"></i>
                        </span>
                      </button>
                    </li>
                <form action="https://metacpan.org/account/logout" method="POST" id="metacpan-logout"></form>
                <li class="dropdown logged_in" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="https://metacpan.org/account/identities">Identities</a></li>
                        <li><a href="https://metacpan.org/account/profile">Profile</a></li>
                        <li><a href="https://metacpan.org/account/favorite/list">Favorites</a></li>
                        <li>
                            <a href="Expect.html#" type="button" onclick="$('#metacpan-logout').submit(); return false">
                              Logout
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_out" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="https://metacpan.org/login/github">
                                <i class="fab fa-github fa-fw"></i>
                                GitHub
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/twitter">
                                <i class="fab fa-twitter fa-fw"></i>
                                Twitter
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/google">
                                <i class="fab fa-google fa-fw"></i>
                                Google
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_placeholder">
                    <button>
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                    </button>
                </li>
            </ul>
        </nav>
        <div class="page-content ">
          <!--
          <div class="top-notify-banner">
            <i class="fas fa-info-circle"></i>
          </div>
          -->
          <nav class="sidebar">
            <div class="slidepanel">
              <ul class="nav-list ">
    <li class="nav-header no-margin-top">
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Expect was released.">
      <span class="relatize">18 May 2017 19:13:49 UTC</span>
    </li>
  <li>
    Distribution: <a href="https://metacpan.org/dist/Expect">Expect</a>
  </li>
  <li>
    Module version: 1.35
  </li>
  <li>
    <a data-keyboard-shortcut="g s" href="https://metacpan.org/dist/Expect/source/lib/Expect.pm">Source</a>
    (<a href="https://metacpan.org/dist/Expect/source/lib/Expect.pm?raw=1">raw</a>)
  </li>
  <li>
    <a data-keyboard-shortcut="g b" href="https://metacpan.org/dist/Expect/source/lib">Browse</a>
    (<a href="https://metacpan.org/dist/Expect/source/lib?raw=1">raw</a>)
  </li>
    <li>
      <a data-keyboard-shortcut="g c" href="https://metacpan.org/dist/Expect/changes">Changes</a>
    </li>
    <li>
      <a class="nopopup" href="https://metacpan.org/dist/Expect/contribute">How to Contribute</a>
    </li>
    <li>
        <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/jacoby/expect.pm">Repository</a>
    </li>
    <li>
      <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=Expect">Issues</a>
      (21)
    </li>
    <li>
      <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Expect+1.35" title="Matrix">Testers</a>
        <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/E/Expect.html?oncpan=1&amp;distmat=1&amp;version=1.35&amp;grade=2" style="color: #090">1105</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/E/Expect.html?oncpan=1&amp;distmat=1&amp;version=1.35&amp;grade=3" style="color: #900">66</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/E/Expect.html?oncpan=1&amp;distmat=1&amp;version=1.35&amp;grade=4">0</a>)</span>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/JACOBY/Expect-1.35">Kwalitee</a>
    </li>
    <li>
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Expect who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)">
      Bus factor: 0
      </div>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpancover.com/latest/Expect-1.35/index.html">49.56% Coverage </a>
    </li>
    <li>
      License: perl_5
    </li>
    <li>
      Perl: v5.6.0
    </li>
    <li class="nav-header">Activity</li>
    <li>
<div class="activity-graph">
    <img src="https://metacpan.org/dist/Expect/activity.svg?res=month" />
    <div class="comment">24 month</div>
</div>
    </li>
    <li class="nav-header">Tools</li>
    <li>
      <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/J/JA/JACOBY/Expect-1.35.tar.gz">
      Download (<span itemprop="fileSize">60.22KB</span>)</a>
    </li>
    <li>
      <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FJACOBY%2FExpect-1.35%2Flib%2FExpect.pm">
        MetaCPAN Explorer
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Expect/permissions">
        Permissions
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Expect/releases.rss">
        Subscribe to distribution
      </a>
    </li>
    <li>
      <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog">
        Install Instructions
      </button>
    </li>
    <li>
      <form action="https://metacpan.org/search">
        <input type="hidden" name="q" value="dist:Expect">
        <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
      </form>
    </li>
    <li>
      <form action="https://grep.metacpan.org/search">
        <input type="hidden" name="qd" value="Expect">
        <input type="hidden" name="source" value="metacpan">
        <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
     </form>
    </li>
    <li class="version-jump">
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Expect.pm&#39;" class="form-control tool-bar-form">
  <option disabled selected>Jump to version</option>
<option
  disabled
  value="JACOBY/Expect-1.35"
>1.35
  (JACOBY on 2017-05-18)</option>
<option
  
  value="JACOBY/Expect-1.34"
>1.34
  (JACOBY on 2017-05-18)</option>
<option
  
  value="JACOBY/Expect-1.33"
>1.33
  (JACOBY on 2016-06-08)</option>
<option
  
  value="JACOBY/Expect-1.32"
>1.32
  (JACOBY on 2015-10-31)</option>
<option
  
  value="RGIERSIG/Expect-1.21"
>1.21
  (RGIERSIG on 2007-08-13)</option>
<option
  
  value="RGIERSIG/Expect-1.20"
>1.20
  (RGIERSIG on 2006-07-21)</option>
<option
  
  value="RGIERSIG/Expect-1.17"
>1.17
  (RGIERSIG on 2006-05-31)</option>
<option
  
  value="RGIERSIG/Expect-1.15"
>1.15
  (RGIERSIG on 2002-03-19)</option>
<option
  
  value="AUSCHUTZ/Expect.pm-1.07"
>1.07
  (AUSCHUTZ on 1998-07-12)</option>
<option
  
  value="AUSCHUTZ/Expect.pm-1.04"
>1.04
  (AUSCHUTZ on 1998-03-12)</option>
<option
  
  value="AUSCHUTZ/Expect.pm-1.01"
>1.01
  (AUSCHUTZ on 1997-12-15)</option>
<optgroup label="BackPAN">'
<option
  
  value="SZABGAB/Expect-1.32"
>1.32
  (SZABGAB on 2014-10-26)</option>
<option
  
  value="SZABGAB/Expect-1.31"
>1.31
  (SZABGAB on 2014-09-02)</option>
<option
  
  value="SZABGAB/Expect-1.30"
>1.30
  (SZABGAB on 2014-08-22)</option>
<option
  
  value="SZABGAB/Expect-1.29"
>1.29
  (SZABGAB on 2014-08-14)</option>
<option
  
  value="SZABGAB/Expect-1.28"
>1.28
  (SZABGAB on 2014-08-14)</option>
<option
  
  value="SZABGAB/Expect-1.27"
>1.27
  (SZABGAB on 2014-08-13)</option>
<option
  
  value="SZABGAB/Expect-1.26"
>1.26
  (SZABGAB on 2014-08-12)</option>
<option
  
  value="SZABGAB/Expect-1.25"
>1.25
  (SZABGAB on 2014-08-05)</option>
<option
  
  value="SZABGAB/Expect-1.24"
>1.24
  (SZABGAB on 2014-08-04)</option>
<option
  
  value="SZABGAB/Expect-1.23"
>1.23
  (SZABGAB on 2014-07-29)</option>
<option
  
  value="SZABGAB/Expect-1.22"
>1.22
  (SZABGAB on 2014-07-27)</option>
<option
  
  value="RGIERSIG/Expect-1.19"
>1.19
  (RGIERSIG on 2006-07-17)</option>
<option
  
  value="RGIERSIG/Expect-1.18"
>1.18
  (RGIERSIG on 2006-07-11)</option>
<option
  
  value="RGIERSIG/Expect-1.16"
>1.16
  (RGIERSIG on 2006-05-05)</option>
<option
  
  value="RGIERSIG/Expect-1.14"
>1.14
  (RGIERSIG on 2002-03-13)</option>
<option
  
  value="RGIERSIG/Expect-1.13_08"
>1.13_08 DEV
  (RGIERSIG on 2002-02-28)</option>
<option
  
  value="RGIERSIG/Expect-1.13_07"
>1.13_07 DEV
  (RGIERSIG on 2002-02-28)</option>
<option
  
  value="RGIERSIG/Expect-1.13_06"
>1.13_06 DEV
  (RGIERSIG on 2002-01-31)</option>
<option
  
  value="RGIERSIG/Expect-1.13_04"
>1.13_04 DEV
  (RGIERSIG on 2002-01-18)</option>
<option
  
  value="RGIERSIG/Expect-1.13_02"
>1.13_02 DEV
  (RGIERSIG on 2001-11-30)</option>
<option
  
  value="RGIERSIG/Expect-1.13_01"
>1.13_01 DEV
  (RGIERSIG on 2001-11-26)</option>
<option
  
  value="RGIERSIG/Expect-1.12"
>1.12
  (RGIERSIG on 2001-09-06)</option>
<option
  
  value="RGIERSIG/Expect-1.11"
>1.11
  (RGIERSIG on 2001-02-20)</option>
<option
  
  value="RGIERSIG/Expect-1.10"
>1.10
  (RGIERSIG on 2000-11-22)</option>
<option
  
  value="RGIERSIG/Expect-1.09"
>1.09
  (RGIERSIG on 2000-11-21)</option>
<option
  
  value="RGIERSIG/Expect-1.08"
>1.08
  (RGIERSIG on 2000-09-20)</option>
</optgroup>
</select>
    </li>
    <li class="version-diff">
<select onchange="document.location.href='/release/JACOBY/Expect-1.35/diff/' + encodeURIComponent(this.value) + '/lib/Expect.pm'
" class="form-control tool-bar-form">
  <option disabled selected>Diff with version</option>
<option
  disabled
  value="JACOBY/Expect-1.35"
>1.35
  (JACOBY on 2017-05-18)</option>
<option
  
  value="JACOBY/Expect-1.34"
>1.34
  (JACOBY on 2017-05-18)</option>
<option
  
  value="JACOBY/Expect-1.33"
>1.33
  (JACOBY on 2016-06-08)</option>
<option
  
  value="JACOBY/Expect-1.32"
>1.32
  (JACOBY on 2015-10-31)</option>
<option
  
  value="RGIERSIG/Expect-1.21"
>1.21
  (RGIERSIG on 2007-08-13)</option>
<option
  
  value="RGIERSIG/Expect-1.20"
>1.20
  (RGIERSIG on 2006-07-21)</option>
<option
  
  value="RGIERSIG/Expect-1.17"
>1.17
  (RGIERSIG on 2006-05-31)</option>
<option
  
  value="RGIERSIG/Expect-1.15"
>1.15
  (RGIERSIG on 2002-03-19)</option>
<option
  
  value="AUSCHUTZ/Expect.pm-1.07"
>1.07
  (AUSCHUTZ on 1998-07-12)</option>
<option
  
  value="AUSCHUTZ/Expect.pm-1.04"
>1.04
  (AUSCHUTZ on 1998-03-12)</option>
<option
  
  value="AUSCHUTZ/Expect.pm-1.01"
>1.01
  (AUSCHUTZ on 1997-12-15)</option>
<optgroup label="BackPAN">'
<option
  
  value="SZABGAB/Expect-1.32"
>1.32
  (SZABGAB on 2014-10-26)</option>
<option
  
  value="SZABGAB/Expect-1.31"
>1.31
  (SZABGAB on 2014-09-02)</option>
<option
  
  value="SZABGAB/Expect-1.30"
>1.30
  (SZABGAB on 2014-08-22)</option>
<option
  
  value="SZABGAB/Expect-1.29"
>1.29
  (SZABGAB on 2014-08-14)</option>
<option
  
  value="SZABGAB/Expect-1.28"
>1.28
  (SZABGAB on 2014-08-14)</option>
<option
  
  value="SZABGAB/Expect-1.27"
>1.27
  (SZABGAB on 2014-08-13)</option>
<option
  
  value="SZABGAB/Expect-1.26"
>1.26
  (SZABGAB on 2014-08-12)</option>
<option
  
  value="SZABGAB/Expect-1.25"
>1.25
  (SZABGAB on 2014-08-05)</option>
<option
  
  value="SZABGAB/Expect-1.24"
>1.24
  (SZABGAB on 2014-08-04)</option>
<option
  
  value="SZABGAB/Expect-1.23"
>1.23
  (SZABGAB on 2014-07-29)</option>
<option
  
  value="SZABGAB/Expect-1.22"
>1.22
  (SZABGAB on 2014-07-27)</option>
<option
  
  value="RGIERSIG/Expect-1.19"
>1.19
  (RGIERSIG on 2006-07-17)</option>
<option
  
  value="RGIERSIG/Expect-1.18"
>1.18
  (RGIERSIG on 2006-07-11)</option>
<option
  
  value="RGIERSIG/Expect-1.16"
>1.16
  (RGIERSIG on 2006-05-05)</option>
<option
  
  value="RGIERSIG/Expect-1.14"
>1.14
  (RGIERSIG on 2002-03-13)</option>
<option
  
  value="RGIERSIG/Expect-1.13_08"
>1.13_08 DEV
  (RGIERSIG on 2002-02-28)</option>
<option
  
  value="RGIERSIG/Expect-1.13_07"
>1.13_07 DEV
  (RGIERSIG on 2002-02-28)</option>
<option
  
  value="RGIERSIG/Expect-1.13_06"
>1.13_06 DEV
  (RGIERSIG on 2002-01-31)</option>
<option
  
  value="RGIERSIG/Expect-1.13_04"
>1.13_04 DEV
  (RGIERSIG on 2002-01-18)</option>
<option
  
  value="RGIERSIG/Expect-1.13_02"
>1.13_02 DEV
  (RGIERSIG on 2001-11-30)</option>
<option
  
  value="RGIERSIG/Expect-1.13_01"
>1.13_01 DEV
  (RGIERSIG on 2001-11-26)</option>
<option
  
  value="RGIERSIG/Expect-1.12"
>1.12
  (RGIERSIG on 2001-09-06)</option>
<option
  
  value="RGIERSIG/Expect-1.11"
>1.11
  (RGIERSIG on 2001-02-20)</option>
<option
  
  value="RGIERSIG/Expect-1.10"
>1.10
  (RGIERSIG on 2000-11-22)</option>
<option
  
  value="RGIERSIG/Expect-1.09"
>1.09
  (RGIERSIG on 2000-11-21)</option>
<option
  
  value="RGIERSIG/Expect-1.08"
>1.08
  (RGIERSIG on 2000-09-20)</option>
</optgroup>
</select>
    </li>

    <li>
<ul class="dependencies">
  <li class="nav-header">Dependencies</li>
  <li><a href="https://metacpan.org/pod/Carp" title="Carp" class="ellipsis">Carp</a></li>
  <li><a href="https://metacpan.org/pod/Errno" title="Errno" class="ellipsis">Errno</a></li>
  <li><a href="https://metacpan.org/pod/Exporter" title="Exporter" class="ellipsis">Exporter</a></li>
  <li><a href="https://metacpan.org/pod/Fcntl" title="Fcntl" class="ellipsis">Fcntl</a></li>
  <li><a href="https://metacpan.org/pod/IO::Handle" title="IO::Handle" class="ellipsis">IO::Handle</a></li>
  <li><a href="./IO::Pty.html" title="IO::Pty" class="ellipsis">IO::Pty</a></li>
  <li><a href="https://metacpan.org/pod/IO::Tty" title="IO::Tty" class="ellipsis">IO::Tty</a></li>
  <li><a href="https://metacpan.org/pod/POSIX" title="POSIX" class="ellipsis">POSIX</a></li>
  <li><i class="ttip" title="dynamic_config enabled">and possibly others</i></li>
  <li>
    <hr>
  </li>
  <li>
    <a href="https://metacpan.org/module/Expect/requires">Reverse dependencies</a>
  </li>
  <li>
    <a href="http://deps.cpantesters.org/?module=Expect">CPAN Testers List</a>
  </li>
  <li>
    <a href="https://cpandeps.grinnz.com/?dist=Expect">Dependency graph</a>
  </li>
</ul>
    </li>
    <li class="nav-header">Permalinks</li>
    <li>
      <a href="https://metacpan.org/release/JACOBY/Expect-1.35/view/lib/Expect.pm">This version</a>
    </li>
    <li>
      <a href="Expect.html">Latest version</a>
    </li>
    <li>
<div class="plussers">
<div class="nav-header">++ed by:</div>
<div>
<a class="display-all" href="https://metacpan.org/author/RWP"><img src="https://www.gravatar.com/avatar/7110eb2389e69a066d9d7cad7a1cc2bf?d=identicon&amp;s=20" title="RWP" alt="RWP"></a>
<a class="display-all" href="https://metacpan.org/author/TOMMY"><img src="https://www.gravatar.com/avatar/0f6d7599a5ecabfa63160d0ee8e92992?d=identicon&amp;s=20" title="TOMMY" alt="TOMMY"></a>
<a class="display-all" href="https://metacpan.org/author/POTATOGIM"><img src="https://www.gravatar.com/avatar/82f1c6258702415af6e26187f1e36850?d=identicon&amp;s=20" title="POTATOGIM" alt="POTATOGIM"></a>
<a class="display-all" href="https://metacpan.org/author/BESSARABV"><img src="https://www.gravatar.com/avatar/f848f8b82e51b7a88ca22562639a814b?d=identicon&amp;s=20" title="BESSARABV" alt="BESSARABV"></a>
<a class="display-all" href="https://metacpan.org/author/PERLANCAR"><img src="https://www.gravatar.com/avatar/c66c9e215cc2342796cd87ca82d044a8?d=identicon&amp;s=20" title="PERLANCAR" alt="PERLANCAR"></a>
</div>
<!-- Display counts of plussers-->
<div>
    <a href="https://metacpan.org/dist/Expect/plussers">17 PAUSE users</a>
</div>
<div>
    10 non-PAUSE users
</div>
</div>
    </li>
    <li>
<div id="metacpan_contributors">
  <div>
    <button class="btn-link"
      onclick="$(this).hide(); $('#metacpan_contributors ul').slideDown(); return false;"
    >and 2 contributors</button>
  </div>
  <ul style="display: none">
    <li class="contributor"
      data-contrib-email="ASchutz@users.sourceforge.net"
    >
      <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" />
      Austin Schutz
    </li>
    <li class="contributor"
      data-cpan-author="RGIERSIG"
      data-contrib-email="RGiersig@cpan.org"
    >
      <a href="https://metacpan.org/author/RGIERSIG" class="cpan-author">
      <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/2c59cbd332368e1df0ff0ca6c212913e?d=identicon&amp;s=20" />
      Roland Giersig
      </a>
    </li>
  </ul>
</div>
    </li>
              </ul>
            </div>
          </nav>
          <div class="content-navigation">
<div class="breadcrumbs">
  <span>
    <a data-keyboard-shortcut="g a" rel="author" href="https://metacpan.org/author/JACOBY" class="author-name">Dave Jacoby</a>
  </span>
  <span>&nbsp;/&nbsp;</span>
  <div class="release dist-release status-latest maturity-released">
    <span class="dropdown"><b class="caret"></b></span>
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Expect.pm&#39;" class="">
<option
  selected
  value="JACOBY/Expect-1.35"
>1.35
  (JACOBY on 2017-05-18)</option>
<option
  
  value="JACOBY/Expect-1.34"
>1.34
  (JACOBY on 2017-05-18)</option>
<option
  
  value="JACOBY/Expect-1.33"
>1.33
  (JACOBY on 2016-06-08)</option>
<option
  
  value="JACOBY/Expect-1.32"
>1.32
  (JACOBY on 2015-10-31)</option>
<option
  
  value="RGIERSIG/Expect-1.21"
>1.21
  (RGIERSIG on 2007-08-13)</option>
<option
  
  value="RGIERSIG/Expect-1.20"
>1.20
  (RGIERSIG on 2006-07-21)</option>
<option
  
  value="RGIERSIG/Expect-1.17"
>1.17
  (RGIERSIG on 2006-05-31)</option>
<option
  
  value="RGIERSIG/Expect-1.15"
>1.15
  (RGIERSIG on 2002-03-19)</option>
<option
  
  value="AUSCHUTZ/Expect.pm-1.07"
>1.07
  (AUSCHUTZ on 1998-07-12)</option>
<option
  
  value="AUSCHUTZ/Expect.pm-1.04"
>1.04
  (AUSCHUTZ on 1998-03-12)</option>
<option
  
  value="AUSCHUTZ/Expect.pm-1.01"
>1.01
  (AUSCHUTZ on 1997-12-15)</option>
<optgroup label="BackPAN">'
<option
  
  value="SZABGAB/Expect-1.32"
>1.32
  (SZABGAB on 2014-10-26)</option>
<option
  
  value="SZABGAB/Expect-1.31"
>1.31
  (SZABGAB on 2014-09-02)</option>
<option
  
  value="SZABGAB/Expect-1.30"
>1.30
  (SZABGAB on 2014-08-22)</option>
<option
  
  value="SZABGAB/Expect-1.29"
>1.29
  (SZABGAB on 2014-08-14)</option>
<option
  
  value="SZABGAB/Expect-1.28"
>1.28
  (SZABGAB on 2014-08-14)</option>
<option
  
  value="SZABGAB/Expect-1.27"
>1.27
  (SZABGAB on 2014-08-13)</option>
<option
  
  value="SZABGAB/Expect-1.26"
>1.26
  (SZABGAB on 2014-08-12)</option>
<option
  
  value="SZABGAB/Expect-1.25"
>1.25
  (SZABGAB on 2014-08-05)</option>
<option
  
  value="SZABGAB/Expect-1.24"
>1.24
  (SZABGAB on 2014-08-04)</option>
<option
  
  value="SZABGAB/Expect-1.23"
>1.23
  (SZABGAB on 2014-07-29)</option>
<option
  
  value="SZABGAB/Expect-1.22"
>1.22
  (SZABGAB on 2014-07-27)</option>
<option
  
  value="RGIERSIG/Expect-1.19"
>1.19
  (RGIERSIG on 2006-07-17)</option>
<option
  
  value="RGIERSIG/Expect-1.18"
>1.18
  (RGIERSIG on 2006-07-11)</option>
<option
  
  value="RGIERSIG/Expect-1.16"
>1.16
  (RGIERSIG on 2006-05-05)</option>
<option
  
  value="RGIERSIG/Expect-1.14"
>1.14
  (RGIERSIG on 2002-03-13)</option>
<option
  
  value="RGIERSIG/Expect-1.13_08"
>1.13_08 DEV
  (RGIERSIG on 2002-02-28)</option>
<option
  
  value="RGIERSIG/Expect-1.13_07"
>1.13_07 DEV
  (RGIERSIG on 2002-02-28)</option>
<option
  
  value="RGIERSIG/Expect-1.13_06"
>1.13_06 DEV
  (RGIERSIG on 2002-01-31)</option>
<option
  
  value="RGIERSIG/Expect-1.13_04"
>1.13_04 DEV
  (RGIERSIG on 2002-01-18)</option>
<option
  
  value="RGIERSIG/Expect-1.13_02"
>1.13_02 DEV
  (RGIERSIG on 2001-11-30)</option>
<option
  
  value="RGIERSIG/Expect-1.13_01"
>1.13_01 DEV
  (RGIERSIG on 2001-11-26)</option>
<option
  
  value="RGIERSIG/Expect-1.12"
>1.12
  (RGIERSIG on 2001-09-06)</option>
<option
  
  value="RGIERSIG/Expect-1.11"
>1.11
  (RGIERSIG on 2001-02-20)</option>
<option
  
  value="RGIERSIG/Expect-1.10"
>1.10
  (RGIERSIG on 2000-11-22)</option>
<option
  
  value="RGIERSIG/Expect-1.09"
>1.09
  (RGIERSIG on 2000-11-21)</option>
<option
  
  value="RGIERSIG/Expect-1.08"
>1.08
  (RGIERSIG on 2000-09-20)</option>
</optgroup>
</select>
    <a data-keyboard-shortcut="g d" class="release-name" href="https://metacpan.org/dist/Expect">Expect-1.35</a>
  </div>
<span class="river-gauge-gauge">
  <svg width="24px"
       height="15px"
       version="1.1"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:xlink="http://www.w3.org/1999/xlink">

    <g>
      <title>        River stage three &#10;
          • 34 direct dependents &#10;          • 580 total dependents
      </title>

      <rect x="0"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="5"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="10"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="15"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="20"  y="0" width="4" height="15" fill="#e4e2e2" />
    </g>
  </svg>

</span>
<div id="Expect-fav" class="logged_in">
<form action="https://metacpan.org/account/favorite/add" style="display: inline" onsubmit="return favDistribution(this)">
    <input type="hidden" name="remove" value="0">
    <input type="hidden" name="release" value="Expect-1.35">
    <input type="hidden" name="author" value="JACOBY">
    <input type="hidden" name="distribution" value="Expect">
    <button type="submit" class="favorite highlight"><span>27</span> ++</button>
</form>
</div>
<div class="logged_out">
<a href="Expect.html" onclick="alert('Please sign in to add favorites'); return false" class="favorite highlight">
<span>27</span> ++</a>
</div>
   / <span>Expect</span>
</div>
          </div>
          <main class="content">


<nav class="toc">
  <div class="toc-header"><strong>Contents</strong></div>
<ul>
  <li><a href="Expect.html#NAME">NAME</a></li>
  <li><a href="Expect.html#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="Expect.html#DESCRIPTION">DESCRIPTION</a></li>
  <li><a href="Expect.html#USAGE">USAGE</a>
    <ul>
      <li><a href="Expect.html#Configurable-Package-Variables:">Configurable Package Variables:</a></li>
    </ul>
  </li>
  <li><a href="Expect.html#CONTRIBUTIONS">CONTRIBUTIONS</a></li>
  <li><a href="Expect.html#REFERENCES">REFERENCES</a></li>
  <li><a href="Expect.html#FAQ-Frequently-Asked-Questions">FAQ - Frequently Asked Questions</a>
    <ul>
      <li><a href="Expect.html#What-systems-does-Expect-run-on?">What systems does Expect run on?</a></li>
      <li><a href="Expect.html#Can-I-use-this-module-with-ActivePerl-on-Windows?">Can I use this module with ActivePerl on Windows?</a></li>
      <li><a href="Expect.html#The-examples-in-the-tutorial-don&#39;t-work!">The examples in the tutorial don&#39;t work!</a></li>
      <li><a href="Expect.html#How-can-I-find-out-what-Expect-is-doing?">How can I find out what Expect is doing?</a></li>
      <li><a href="Expect.html#I-am-seeing-the-output-of-the-command-I-spawned.-Can-I-turn-that-off?">I am seeing the output of the command I spawned. Can I turn that off?</a></li>
      <li><a href="Expect.html#No,-I-mean-that-when-I-send-some-text-to-the-spawned-process,-it-gets-echoed-back-and-I-have-to-deal-with-it-in-the-next-expect.">No, I mean that when I send some text to the spawned process, it gets echoed back and I have to deal with it in the next expect.</a></li>
      <li><a href="Expect.html#How-do-I-send-control-characters-to-a-process?">How do I send control characters to a process?</a></li>
      <li><a href="Expect.html#My-script-fails-from-time-to-time-without-any-obvious-reason.-It-seems-that-I-am-sometimes-loosing-output-from-the-spawned-program.">My script fails from time to time without any obvious reason. It seems that I am sometimes loosing output from the spawned program.</a></li>
      <li><a href="Expect.html#I-want-to-automate-password-entry-for-su/ssh/scp/rsh/...">I want to automate password entry for su/ssh/scp/rsh/...</a></li>
      <li><a href="Expect.html#I-want-to-use-Expect-to-automate-%5Banything-with-a-buzzword%5D...">I want to use Expect to automate [anything with a buzzword]...</a></li>
      <li><a href="Expect.html#Is-it-possible-to-use-threads-with-Expect?">Is it possible to use threads with Expect?</a></li>
      <li><a href="Expect.html#I-want-to-log-the-whole-session-to-a-file.">I want to log the whole session to a file.</a></li>
      <li><a href="Expect.html#How-can-I-turn-off-multi-line-matching-for-my-regexps?">How can I turn off multi-line matching for my regexps?</a></li>
      <li><a href="Expect.html#How-can-I-expect-on-multiple-spawned-commands?">How can I expect on multiple spawned commands?</a></li>
      <li><a href="Expect.html#I-seem-to-have-problems-with-ptys!">I seem to have problems with ptys!</a></li>
      <li><a href="Expect.html#I-just-want-to-read-the-output-of-a-process-without-expect()ing-anything.-How-can-I-do-this?">I just want to read the output of a process without expect()ing anything. How can I do this?</a></li>
      <li><a href="Expect.html#Ok,-so-now-how-do-I-get-what-was-read-on-the-handle?">Ok, so now how do I get what was read on the handle?</a></li>
      <li><a href="Expect.html#Where&#39;s-IO::Pty?">Where&#39;s IO::Pty?</a></li>
      <li><a href="Expect.html#How-come-when-I-automate-the-passwd-program-to-change-passwords-for-me-passwd-dies-before-changing-the-password-sometimes/every-time?">How come when I automate the passwd program to change passwords for me passwd dies before changing the password sometimes/every time?</a></li>
      <li><a href="Expect.html#How-come-when-I-try-to-make-a-logfile-with-log_file()-or-set_group()-it-doesn&#39;t-print-anything-after-the-last-time-I-run-expect()?">How come when I try to make a logfile with log_file() or set_group() it doesn&#39;t print anything after the last time I run expect()?</a></li>
      <li><a href="Expect.html#I-seem-to-have-problems-with-terminal-settings,-double-echoing,-etc.">I seem to have problems with terminal settings, double echoing, etc.</a></li>
      <li><a href="Expect.html#I&#39;m-spawning-a-telnet/ssh-session-and-then-let-the-user-interact-with-it.-But-screen-oriented-applications-on-the-other-side-don&#39;t-work-properly.">I&#39;m spawning a telnet/ssh session and then let the user interact with it. But screen-oriented applications on the other side don&#39;t work properly.</a></li>
      <li><a href="Expect.html#I-set-the-terminal-size-as-explained-above,-but-if-I-resize-the-window,-the-application-does-not-notice-this.">I set the terminal size as explained above, but if I resize the window, the application does not notice this.</a></li>
      <li><a href="Expect.html#I-noticed-that-the-test-uses-a-string-that-resembles,-but-not-exactly-matches,-a-well-known-sentence-that-contains-every-character.-What-does-that-mean?">I noticed that the test uses a string that resembles, but not exactly matches, a well-known sentence that contains every character. What does that mean?</a></li>
      <li><a href="Expect.html#I-get-a-%22Could-not-assign-a-pty%22-error-when-running-as-a-non-root-user-on-an-IRIX-box?">I get a &quot;Could not assign a pty&quot; error when running as a non-root user on an IRIX box?</a></li>
      <li><a href="Expect.html#How-come-I-don&#39;t-notice-when-the-spawned-process-closes-its-stdin/out/err??">How come I don&#39;t notice when the spawned process closes its stdin/out/err??</a></li>
    </ul>
  </li>
  <li><a href="Expect.html#Source-Examples">Source Examples</a>
    <ul>
      <li><a href="Expect.html#How-to-automate-login">How to automate login</a></li>
      <li><a href="Expect.html#How-to-expect-on-multiple-spawned-commands">How to expect on multiple spawned commands</a></li>
      <li><a href="Expect.html#How-to-propagate-terminal-sizes">How to propagate terminal sizes</a></li>
    </ul>
  </li>
  <li><a href="Expect.html#HOMEPAGE">HOMEPAGE</a></li>
  <li><a href="Expect.html#MAILING-LISTS">MAILING LISTS</a></li>
  <li><a href="Expect.html#BUG-TRACKING">BUG TRACKING</a></li>
  <li><a href="Expect.html#AUTHORS">AUTHORS</a></li>
  <li><a href="Expect.html#LICENSE">LICENSE</a></li>
  <li><a href="Expect.html#DISCLAIMER">DISCLAIMER</a></li>
</ul></nav>
<div class="pod anchors">
<h1 id="NAME">NAME</h1>

<p>Expect - automate interactions with command line programs that expose a text terminal interface.</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code>  use Expect;

  # create an Expect object by spawning another process
  my $exp = Expect-&gt;spawn($command, @params)
    or die &quot;Cannot spawn $command: $!\n&quot;;

  # or by using an already opened filehandle (e.g. from Net::Telnet)
  my $exp = Expect-&gt;exp_init(\*FILEHANDLE);

  # if you prefer the OO mindset:
  my $exp = Expect-&gt;new;
  $exp-&gt;raw_pty(1);
  $exp-&gt;spawn($command, @parameters)
    or die &quot;Cannot spawn $command: $!\n&quot;;

  # send some string there:
  $exp-&gt;send(&quot;string\n&quot;);

  # or, for the filehandle mindset:
  print $exp &quot;string\n&quot;;

  # then do some pattern matching with either the simple interface
  $patidx = $exp-&gt;expect($timeout, @match_patterns);

  # or multi-match on several spawned commands with callbacks,
  # just like the Tcl version
  $exp-&gt;expect($timeout,
             [ qr/regex1/ =&gt; sub { my $exp = shift;
                       $exp-&gt;send(&quot;response\n&quot;);
                       exp_continue; } ],
             [ &quot;regexp2&quot; , \&amp;callback, @cbparms ],
            );

  # if no longer needed, do a soft_close to nicely shut down the command
  $exp-&gt;soft_close();

  # or be less patient with
  $exp-&gt;hard_close();</code></pre>

<p>Expect.pm is built to either spawn a process or take an existing filehandle and interact with it such that normally interactive tasks can be done without operator assistance. This concept makes more sense if you are already familiar with the versatile Tcl version of Expect. The public functions that make up Expect.pm are:</p>

<pre><code>  Expect-&gt;new()
  Expect::interconnect(@objects_to_be_read_from)
  Expect::test_handles($timeout, @objects_to_test)
  Expect::version($version_requested | undef);
  $object-&gt;spawn(@command)
  $object-&gt;clear_accum()
  $object-&gt;set_accum($value)
  $object-&gt;debug($debug_level)
  $object-&gt;exp_internal(0 | 1)
  $object-&gt;notransfer(0 | 1)
  $object-&gt;raw_pty(0 | 1)
  $object-&gt;stty(@stty_modes) # See the IO::Stty docs
  $object-&gt;slave()
  $object-&gt;before();
  $object-&gt;match();
  $object-&gt;after();
  $object-&gt;matchlist();
  $object-&gt;match_number();
  $object-&gt;error();
  $object-&gt;command();
  $object-&gt;exitstatus();
  $object-&gt;pty_handle();
  $object-&gt;do_soft_close();
  $object-&gt;restart_timeout_upon_receive(0 | 1);
  $object-&gt;interact($other_object, $escape_sequence)
  $object-&gt;log_group(0 | 1 | undef)
  $object-&gt;log_user(0 | 1 | undef)
  $object-&gt;log_file(&quot;filename&quot; | $filehandle | \&amp;coderef | undef)
  $object-&gt;manual_stty(0 | 1 | undef)
  $object-&gt;match_max($max_buffersize or undef)
  $object-&gt;pid();
  $object-&gt;send_slow($delay, @strings_to_send)
  $object-&gt;set_group(@listen_group_objects | undef)
  $object-&gt;set_seq($sequence,\&amp;function,\@parameters);</code></pre>

<p>There are several configurable package variables that affect the behavior of Expect. They are:</p>

<pre><code>  $Expect::Debug;
  $Expect::Exp_Internal;
  $Expect::IgnoreEintr;
  $Expect::Log_Group;
  $Expect::Log_Stdout;
  $Expect::Manual_Stty;
  $Expect::Multiline_Matching;
  $Expect::Do_Soft_Close;</code></pre>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>See an explanation of <a href="http://code-maven.com/expect">What is Expect</a></p>

<p>The Expect module is a successor of Comm.pl and a descendent of Chat.pl. It more closely resembles the Tcl Expect language than its predecessors. It does not contain any of the networking code found in Comm.pl. I suspect this would be obsolete anyway given the advent of IO::Socket and external tools such as netcat.</p>

<p>Expect.pm is an attempt to have more of a switch() &amp; case feeling to make decision processing more fluid. Three separate types of debugging have been implemented to make code production easier.</p>

<p>It is possible to interconnect multiple file handles (and processes) much like Tcl&#39;s Expect. An attempt was made to enable all the features of Tcl&#39;s Expect without forcing Tcl on the victim programmer :-) .</p>

<p>Please, before you consider using Expect, read the FAQs about <a href="Expect.html#I-want-to-automate-password-entry-for-su/ssh/scp/rsh/...">&quot;I want to automate password entry for su/ssh/scp/rsh/...&quot;</a> and <a href="Expect.html#I-want-to-use-Expect-to-automate-%5Banything-with-a-buzzword%5D...">&quot;I want to use Expect to automate [anything with a buzzword]...&quot;</a></p>

<h1 id="USAGE">USAGE</h1>

<dl>

<dt id="new">new</dt>
<dd>

<p>Creates a new Expect object, i.e. a pty. You can change parameters on it before actually spawning a command. This is important if you want to modify the terminal settings for the slave. See slave() below. The object returned is actually a reblessed IO::Pty filehandle, so see there for additional methods.</p>

</dd>
<dt id="Expect-&gt;exp_init(\*FILEHANDLE)-or"><a id="Expect"></a><a id="Expect--exp_init-FILEHANDLE--or"></a>Expect-&gt;exp_init(\*FILEHANDLE) <i>or</i></dt>
<dd>

</dd>
<dt id="Expect-&gt;init(\*FILEHANDLE)"><a id="Expect1"></a><a id="Expect--init-FILEHANDLE"></a>Expect-&gt;init(\*FILEHANDLE)</dt>
<dd>

<p>Initializes $new_handle_object for use with other Expect functions. It must be passed a <b>_reference_</b> to FILEHANDLE if you want it to work properly. IO::File objects are preferable. Returns a reference to the newly created object.</p>

<p>You can use only real filehandles, certain tied filehandles (e.g. Net::SSH2) that lack a fileno() will not work. Net::Telnet objects can be used but have been reported to work only for certain hosts. YMMV.</p>

</dd>
<dt id="Expect-&gt;spawn($command,-@parameters)-or"><a id="Expect2"></a><a id="Expect--spawn-command---parameters--or"></a>Expect-&gt;spawn($command, @parameters) <i>or</i></dt>
<dd>

</dd>
<dt id="$object-&gt;spawn($command,-@parameters)-or"><a id="object--spawn-command---parameters--or"></a>$object-&gt;spawn($command, @parameters) <i>or</i></dt>
<dd>

</dd>
<dt id="Expect-&gt;new($command,-@parameters)"><a id="Expect3"></a><a id="Expect--new-command---parameters"></a>Expect-&gt;new($command, @parameters)</dt>
<dd>

<p>Forks and execs $command. Returns an Expect object upon success or <code>undef</code> if the fork was unsuccessful or the command could not be found. spawn() passes its parameters unchanged to Perls exec(), so look there for detailed semantics.</p>

<p>Note that if spawn cannot exec() the given command, the Expect object is still valid and the next expect() will see &quot;Cannot exec&quot;, so you can use that for error handling.</p>

<p>Also note that you cannot reuse an object with an already spawned command, even if that command has exited. Sorry, but you have to allocate a new object...</p>

</dd>
<dt id="$object-&gt;debug(0-|-1-|-2-|-3-|-undef)"><a id="object--debug-0---1---2---3---undef"></a>$object-&gt;debug(0 | 1 | 2 | 3 | undef)</dt>
<dd>

<p>Sets debug level for $object. 1 refers to general debugging information, 2 refers to verbose debugging and 0 refers to no debugging. If you call debug() with no parameters it will return the current debugging level. When the object is created the debugging level will match that $Expect::Debug, normally 0.</p>

<p>The &#39;3&#39; setting is new with 1.05, and adds the additional functionality of having the _full_ accumulated buffer printed every time data is read from an Expect object. This was implemented by request. I recommend against using this unless you think you need it as it can create quite a quantity of output under some circumstances..</p>

</dd>
<dt id="$object-&gt;exp_internal(1-|-0)"><a id="object--exp_internal-1---0"></a>$object-&gt;exp_internal(1 | 0)</dt>
<dd>

<p>Sets/unsets &#39;exp_internal&#39; debugging. This is similar in nature to its Tcl counterpart. It is extremely valuable when debugging expect() sequences. When the object is created the exp_internal setting will match the value of $Expect::Exp_Internal, normally 0. Returns the current setting if called without parameters. It is highly recommended that you make use of the debugging features lest you have angry code.</p>

</dd>
<dt id="$object-&gt;raw_pty(1-|-0)"><a id="object--raw_pty-1---0"></a>$object-&gt;raw_pty(1 | 0)</dt>
<dd>

<p>Set pty to raw mode before spawning. This disables echoing, CR-&gt;LF translation and an ugly hack for broken Solaris TTYs (which send &lt;space&gt;&lt;backspace&gt; to slow things down) and thus gives a more pipe-like behaviour (which is important if you want to transfer binary content). Note that this must be set <i>before</i> spawning the program.</p>

</dd>
<dt id="$object-&gt;stty(qw(mode1-mode2...))"><a id="object--stty-qw-mode1-mode2"></a>$object-&gt;stty(qw(mode1 mode2...))</dt>
<dd>

<p>Sets the tty mode for $object&#39;s associated terminal to the given modes. Note that on many systems the master side of the pty is not a tty, so you have to modify the slave pty instead, see next item. This needs IO::Stty installed, which is no longer required.</p>

</dd>
<dt id="$object-&gt;slave()"><a id="object--slave"></a>$object-&gt;slave()</dt>
<dd>

<p>Returns a filehandle to the slave part of the pty. Very useful in modifying the terminal settings:</p>

<pre><code>  $object-&gt;slave-&gt;stty(qw(raw -echo));</code></pre>

<p>Typical values are &#39;sane&#39;, &#39;raw&#39;, and &#39;raw -echo&#39;. Note that I recommend setting the terminal to &#39;raw&#39; or &#39;raw -echo&#39;, as this avoids a lot of hassle and gives pipe-like (i.e. transparent) behaviour (without the buffering issue).</p>

</dd>
<dt id="$object-&gt;print(@strings)-or"><a id="object--print-strings--or"></a>$object-&gt;print(@strings) <i>or</i></dt>
<dd>

</dd>
<dt id="$object-&gt;send(@strings)"><a id="object--send-strings"></a>$object-&gt;send(@strings)</dt>
<dd>

<p>Sends the given strings to the spawned command. Note that the strings are not logged in the logfile (see print_log_file) but will probably be echoed back by the pty, depending on pty settings (default is echo) and thus end up there anyway. This must also be taken into account when expect()ing for an answer: the next string will be the command just sent. I suggest setting the pty to raw, which disables echo and makes the pty transparently act like a bidirectional pipe.</p>

</dd>
<dt id="$object-&gt;expect($timeout,-@match_patterns)"><a id="object--expect-timeout---match_patterns"></a>$object-&gt;expect($timeout, @match_patterns)</dt>
<dd>

<dl>

<dt id="Simple-interface"><a id="Simple"></a>Simple interface</dt>
<dd>

<p>Given $timeout in seconds Expect will wait for $object&#39;s handle to produce one of the match_patterns, which are matched exactly by default. If you want a regexp match, prefix the pattern with &#39;-re&#39;.</p>

<pre><code>  $object-&gt;expect(15, &#39;match me exactly&#39;,&#39;-re&#39;,&#39;match\s+me\s+exactly&#39;);</code></pre>

<p>Due to o/s limitations $timeout should be a round number. If $timeout is 0 Expect will check one time to see if $object&#39;s handle contains any of the match_patterns. If $timeout is undef Expect will wait forever for a pattern to match.</p>

<p>If called in a scalar context, expect() will return the position of the matched pattern within @matched_patterns, or undef if no pattern was matched. This is a position starting from 1, so if you want to know which of an array of @matched_patterns matched you should subtract one from the return value.</p>

<p>If called in an array context expect() will return ($matched_pattern_position, $error, $successfully_matching_string, $before_match, and $after_match).</p>

<p><code>$matched_pattern_position</code> will contain the value that would have been returned if expect() had been called in a scalar context.</p>

<p><code>$error</code> is the error that occurred that caused expect() to return. $error will contain a number followed by a string equivalent expressing the nature of the error. Possible values are undef, indicating no error, &#39;1:TIMEOUT&#39; indicating that $timeout seconds had elapsed without a match, &#39;2:EOF&#39; indicating an eof was read from $object, &#39;3: spawn id($fileno) died&#39; indicating that the process exited before matching and &#39;4:$!&#39; indicating whatever error was set in $ERRNO during the last read on $object&#39;s handle or during select(). All handles indicated by set_group plus STDOUT will have all data to come out of $object printed to them during expect() if log_group and log_stdout are set.</p>

<p><code>$successfully_matching_string</code> <code>$before_match</code> <code>$after_match</code></p>

<p>Changed from older versions is the regular expression handling. By default now all strings passed to expect() are treated as literals. To match a regular expression pass &#39;-re&#39; as a parameter in front of the pattern you want to match as a regexp.</p>

<p>This change makes it possible to match literals and regular expressions in the same expect() call.</p>

<p>Also new is multiline matching. ^ will now match the beginning of lines. Unfortunately, because perl doesn&#39;t use $/ in determining where lines break using $ to find the end of a line frequently doesn&#39;t work. This is because your terminal is returning &quot;\r\n&quot; at the end of every line. One way to check for a pattern at the end of a line would be to use \r?$ instead of $.</p>

<p>Example: Spawning telnet to a host, you might look for the escape character. telnet would return to you &quot;\r\nEscape character is &#39;^]&#39;.\r\n&quot;. To find this you might use $match=&#39;^Escape char.*\.\r?$&#39;;</p>

<pre><code>  $telnet-&gt;expect(10,&#39;-re&#39;,$match);</code></pre>

</dd>
<dt id="New-more-Tcl/Expect-like-interface"><a id="New"></a><a id="New-more-Tcl-Expect-like-interface"></a>New more Tcl/Expect-like interface</dt>
<dd>

<pre><code>  expect($timeout,
       &#39;-i&#39;, [ $obj1, $obj2, ... ],
             [ $re_pattern, sub { ...; exp_continue; }, @subparms, ],
             [ &#39;eof&#39;, sub { ... } ],
             [ &#39;timeout&#39;, sub { ... }, \$subparm1 ],
       &#39;-i&#39;, [ $objn, ...],
       &#39;-ex&#39;, $exact_pattern, sub { ... },
              $exact_pattern, sub { ...; exp_continue_timeout; },
       &#39;-re&#39;, $re_pattern, sub { ... },
       &#39;-i&#39;, \@object_list, @pattern_list,
       ...);</code></pre>

<p>It&#39;s now possible to expect on more than one connection at a time by specifying &#39;<code>-i</code>&#39; and a single Expect object or a ref to an array containing Expect objects, e.g.</p>

<pre><code> expect($timeout,
        &#39;-i&#39;, $exp1, @patterns_1,
        &#39;-i&#39;, [ $exp2, $exp3 ], @patterns_2_3,
       )</code></pre>

<p>Furthermore, patterns can now be specified as array refs containing [$regexp, sub { ...}, @optional_subprams] . When the pattern matches, the subroutine is called with parameters ($matched_expect_obj, @optional_subparms). The subroutine can return the symbol `exp_continue&#39; to continue the expect matching with timeout starting anew or return the symbol `exp_continue_timeout&#39; for continuing expect without resetting the timeout count.</p>

<pre><code> $exp-&gt;expect($timeout,
              [ qr/username: /i, sub { my $self = shift;
                                       $self-&gt;send(&quot;$username\n&quot;);
                                       exp_continue; }],
              [ qr/password: /i, sub { my $self = shift;
                                       $self-&gt;send(&quot;$password\n&quot;);
                                       exp_continue; }],
             $shell_prompt);</code></pre>

<p>`expect&#39; is now exported by default.</p>

</dd>
</dl>

</dd>
<dt id="$object-&gt;exp_before()-or"><a id="object--exp_before--or"></a>$object-&gt;exp_before() <i>or</i></dt>
<dd>

</dd>
<dt id="$object-&gt;before()"><a id="object--before"></a>$object-&gt;before()</dt>
<dd>

<p>before() returns the &#39;before&#39; part of the last expect() call. If the last expect() call didn&#39;t match anything, exp_before() will return the entire output of the object accumulated before the expect() call finished.</p>

<p>Note that this is something different than Tcl Expects before()!!</p>

</dd>
<dt id="$object-&gt;exp_after()-or"><a id="object--exp_after--or"></a>$object-&gt;exp_after() <i>or</i></dt>
<dd>

</dd>
<dt id="$object-&gt;after()"><a id="object--after"></a>$object-&gt;after()</dt>
<dd>

<p>returns the &#39;after&#39; part of the last expect() call. If the last expect() call didn&#39;t match anything, exp_after() will return undef().</p>

</dd>
<dt id="$object-&gt;exp_match()-or"><a id="object--exp_match--or"></a>$object-&gt;exp_match() <i>or</i></dt>
<dd>

</dd>
<dt id="$object-&gt;match()"><a id="object--match"></a>$object-&gt;match()</dt>
<dd>

<p>returns the string matched by the last expect() call, undef if no string was matched.</p>

</dd>
<dt id="$object-&gt;exp_match_number()-or"><a id="object--exp_match_number--or"></a>$object-&gt;exp_match_number() <i>or</i></dt>
<dd>

</dd>
<dt id="$object-&gt;match_number()"><a id="object--match_number"></a>$object-&gt;match_number()</dt>
<dd>

<p>exp_match_number() returns the number of the pattern matched by the last expect() call. Keep in mind that the first pattern in a list of patterns is 1, not 0. Returns undef if no pattern was matched.</p>

</dd>
<dt id="$object-&gt;exp_matchlist()-or"><a id="object--exp_matchlist--or"></a>$object-&gt;exp_matchlist() <i>or</i></dt>
<dd>

</dd>
<dt id="$object-&gt;matchlist()"><a id="object--matchlist"></a>$object-&gt;matchlist()</dt>
<dd>

<p>exp_matchlist() returns a list of matched substrings from the brackets () inside the regexp that last matched. ($object-&gt;matchlist)[0] thus corresponds to $1, ($object-&gt;matchlist)[1] to $2, etc.</p>

</dd>
<dt id="$object-&gt;exp_error()-or"><a id="object--exp_error--or"></a>$object-&gt;exp_error() <i>or</i></dt>
<dd>

</dd>
<dt id="$object-&gt;error()"><a id="object--error"></a>$object-&gt;error()</dt>
<dd>

<p>exp_error() returns the error generated by the last expect() call if no pattern was matched. It is typically useful to examine the value returned by before() to find out what the output of the object was in determining why it didn&#39;t match any of the patterns.</p>

</dd>
<dt id="$object-&gt;clear_accum()"><a id="object--clear_accum"></a>$object-&gt;clear_accum()</dt>
<dd>

<p>Clear the contents of the accumulator for $object. This gets rid of any residual contents of a handle after expect() or send_slow() such that the next expect() call will only see new data from $object. The contents of the accumulator are returned.</p>

</dd>
<dt id="$object-&gt;set_accum($value)"><a id="object--set_accum-value"></a>$object-&gt;set_accum($value)</dt>
<dd>

<p>Sets the content of the accumulator for $object to $value. The previous content of the accumulator is returned.</p>

</dd>
<dt id="$object-&gt;exp_command()-or"><a id="object--exp_command--or"></a>$object-&gt;exp_command() <i>or</i></dt>
<dd>

</dd>
<dt id="$object-&gt;command()"><a id="object--command"></a>$object-&gt;command()</dt>
<dd>

<p>exp_command() returns the string that was used to spawn the command. Helpful for debugging and for reused patternmatch subroutines.</p>

</dd>
<dt id="$object-&gt;exp_exitstatus()-or"><a id="object--exp_exitstatus--or"></a>$object-&gt;exp_exitstatus() <i>or</i></dt>
<dd>

</dd>
<dt id="$object-&gt;exitstatus()"><a id="object--exitstatus"></a>$object-&gt;exitstatus()</dt>
<dd>

<p>Returns the exit status of $object (if it already exited).</p>

</dd>
<dt id="$object-&gt;exp_pty_handle()-or"><a id="object--exp_pty_handle--or"></a>$object-&gt;exp_pty_handle() <i>or</i></dt>
<dd>

</dd>
<dt id="$object-&gt;pty_handle()"><a id="object--pty_handle"></a>$object-&gt;pty_handle()</dt>
<dd>

<p>Returns a string representation of the attached pty, for example: `spawn id(5)&#39; (pty has fileno 5), `handle id(7)&#39; (pty was initialized from fileno 7) or `STDIN&#39;. Useful for debugging.</p>

</dd>
<dt id="$object-&gt;restart_timeout_upon_receive(0-|-1)"><a id="object--restart_timeout_upon_receive-0---1"></a>$object-&gt;restart_timeout_upon_receive(0 | 1)</dt>
<dd>

<p>If this is set to 1, the expect timeout is retriggered whenever something is received from the spawned command. This allows to perform some aliveness testing and still expect for patterns.</p>

<pre><code>    $exp-&gt;restart_timeout_upon_receive(1);
    $exp-&gt;expect($timeout,
                 [ timeout =&gt; \&amp;report_timeout ],
                 [ qr/pattern/ =&gt; \&amp;handle_pattern],
                );</code></pre>

<p>Now the timeout isn&#39;t triggered if the command produces any kind of output, i.e. is still alive, but you can act upon patterns in the output.</p>

</dd>
<dt id="$object-&gt;notransfer(1-|-0)"><a id="object--notransfer-1---0"></a>$object-&gt;notransfer(1 | 0)</dt>
<dd>

<p>Do not truncate the content of the accumulator after a match. Normally, the accumulator is set to the remains that come after the matched string. Note that this setting is per object and not per pattern, so if you want to have normal acting patterns that truncate the accumulator, you have to add a</p>

<pre><code>    $exp-&gt;set_accum($exp-&gt;after);</code></pre>

<p>to their callback, e.g.</p>

<pre><code>    $exp-&gt;notransfer(1);
    $exp-&gt;expect($timeout,
                 # accumulator not truncated, pattern1 will match again
                 [ &quot;pattern1&quot; =&gt; sub { my $self = shift;
                                       ...
                                     } ],
                 # accumulator truncated, pattern2 will not match again
                 [ &quot;pattern2&quot; =&gt; sub { my $self = shift;
                                       ...
                                       $self-&gt;set_accum($self-&gt;after());
                                     } ],
                );</code></pre>

<p>This is only a temporary fix until I can rewrite the pattern matching part so it can take that additional -notransfer argument.</p>

</dd>
<dt id="Expect::interconnect(@objects);"><a id="Expect4"></a><a id="Expect::interconnect-objects"></a>Expect::interconnect(@objects);</dt>
<dd>

<p>Read from @objects and print to their @listen_groups until an escape sequence is matched from one of @objects and the associated function returns 0 or undef. The special escape sequence &#39;EOF&#39; is matched when an object&#39;s handle returns an end of file. Note that it is not necessary to include objects that only accept data in @objects since the escape sequence is _read_ from an object. Further note that the listen_group for a write-only object is always empty. Why would you want to have objects listening to STDOUT (for example)? By default every member of @objects _as well as every member of its listen group_ will be set to &#39;raw -echo&#39; for the duration of interconnection. Setting $object-&gt;manual_stty() will stop this behavior per object. The original tty settings will be restored as interconnect exits.</p>

<p>For a generic way to interconnect processes, take a look at <a href="./IPC::Run.html">IPC::Run</a>.</p>

</dd>
<dt id="Expect::test_handles(@objects)"><a id="Expect5"></a><a id="Expect::test_handles-objects"></a>Expect::test_handles(@objects)</dt>
<dd>

<p>Given a set of objects determines which objects&#39; handles have data ready to be read. <b>Returns an array</b> who&#39;s members are positions in @objects that have ready handles. Returns undef if there are no such handles ready.</p>

</dd>
<dt id="Expect::version($version_requested-or-undef);"><a id="Expect6"></a><a id="Expect::version-version_requested-or-undef"></a>Expect::version($version_requested or undef);</dt>
<dd>

<p>Returns current version of Expect. As of .99 earlier versions are not supported. Too many things were changed to make versioning possible.</p>

</dd>
<dt id="$object-&gt;interact(-\*FILEHANDLE,-$escape_sequence)"><a id="object--interact---FILEHANDLE---escape_sequence"></a>$object-&gt;interact( <code>\*FILEHANDLE, $escape_sequence</code>)</dt>
<dd>

<p>interact() is essentially a macro for calling interconnect() for connecting 2 processes together. \*FILEHANDLE defaults to \*STDIN and $escape_sequence defaults to undef. Interaction ceases when $escape_sequence is read from <b>FILEHANDLE</b>, not $object. $object&#39;s listen group will consist solely of \*FILEHANDLE for the duration of the interaction. \*FILEHANDLE will not be echoed on STDOUT.</p>

</dd>
<dt id="$object-&gt;log_group(0-|-1-|-undef)"><a id="object--log_group-0---1---undef"></a>$object-&gt;log_group(0 | 1 | undef)</dt>
<dd>

<p>Set/unset logging of $object to its &#39;listen group&#39;. If set all objects in the listen group will have output from $object printed to them during $object-&gt;expect(), $object-&gt;send_slow(), and <code>Expect::interconnect($object , ...)</code>. Default value is on. During creation of $object the setting will match the value of $Expect::Log_Group, normally 1.</p>

</dd>
<dt id="$object-&gt;log_user(0-|-1-|-undef)-or"><a id="object--log_user-0---1---undef--or"></a>$object-&gt;log_user(0 | 1 | undef) <i>or</i></dt>
<dd>

</dd>
<dt id="$object-&gt;log_stdout(0-|-1-|-undef)"><a id="object--log_stdout-0---1---undef"></a>$object-&gt;log_stdout(0 | 1 | undef)</dt>
<dd>

<p>Set/unset logging of object&#39;s handle to STDOUT. This corresponds to Tcl&#39;s log_user variable. Returns current setting if called without parameters. Default setting is off for initialized handles. When a process object is created (not a filehandle initialized with exp_init) the log_stdout setting will match the value of $Expect::Log_Stdout variable, normally 1. If/when you initialize STDIN it is usually associated with a tty which will by default echo to STDOUT anyway, so be careful or you will have multiple echoes.</p>

</dd>
<dt id="$object-&gt;log_file(&quot;filename&quot;-|-$filehandle-|-\&amp;coderef-|-undef)"><a id="object--log_file-filename-----filehandle----coderef---undef"></a>$object-&gt;log_file(&quot;filename&quot; | $filehandle | \&amp;coderef | undef)</dt>
<dd>

<p>Log session to a file. All characters send to or received from the spawned process are written to the file. Normally appends to the logfile, but you can pass an additional mode of &quot;w&quot; to truncate the file upon open():</p>

<pre><code>  $object-&gt;log_file(&quot;filename&quot;, &quot;w&quot;);</code></pre>

<p>Returns the logfilehandle.</p>

<p>If called with an undef value, stops logging and closes logfile:</p>

<pre><code>  $object-&gt;log_file(undef);</code></pre>

<p>If called without argument, returns the logfilehandle:</p>

<pre><code>  $fh = $object-&gt;log_file();</code></pre>

<p>Can be set to a code ref, which will be called instead of printing to the logfile:</p>

<pre><code>  $object-&gt;log_file(\&amp;myloggerfunc);</code></pre>

</dd>
<dt id="$object-&gt;print_log_file(@strings)"><a id="object--print_log_file-strings"></a>$object-&gt;print_log_file(@strings)</dt>
<dd>

<p>Prints to logfile (if opened) or calls the logfile hook function. This allows the user to add arbitrary text to the logfile. Note that this could also be done as $object-&gt;log_file-&gt;print() but would only work for log files, not code hooks.</p>

</dd>
<dt id="$object-&gt;set_seq($sequence,-\&amp;function,-\@function_parameters)"><a id="object--set_seq-sequence---function---function_parameters"></a>$object-&gt;set_seq($sequence, \&amp;function, \@function_parameters)</dt>
<dd>

<p>During Expect-&gt;interconnect() if $sequence is read from $object &amp;function will be executed with parameters @function_parameters. It is <b>_highly recommended_</b> that the escape sequence be a single character since the likelihood is great that the sequence will be broken into to separate reads from the $object&#39;s handle, making it impossible to strip $sequence from getting printed to $object&#39;s listen group. \&amp;function should be something like &#39;main::control_w_function&#39; and @function_parameters should be an array defined by the caller, passed by reference to set_seq(). Your function should return a non-zero value if execution of interconnect() is to resume after the function returns, zero or undefined if interconnect() should return after your function returns. The special sequence &#39;EOF&#39; matches the end of file being reached by $object. See interconnect() for details.</p>

</dd>
<dt id="$object-&gt;set_group(@listener_objects)"><a id="object--set_group-listener_objects"></a>$object-&gt;set_group(@listener_objects)</dt>
<dd>

<p>@listener_objects is the list of objects that should have their handles printed to by $object when Expect::interconnect, $object-&gt;expect() or $object-&gt;send_slow() are called. Calling w/out parameters will return the current list of the listener objects.</p>

</dd>
<dt id="$object-&gt;manual_stty(0-|-1-|-undef)"><a id="object--manual_stty-0---1---undef"></a>$object-&gt;manual_stty(0 | 1 | undef)</dt>
<dd>

<p>Sets/unsets whether or not Expect should make reasonable guesses as to when and how to set tty parameters for $object. Will match $Expect::Manual_Stty value (normally 0) when $object is created. If called without parameters manual_stty() will return the current manual_stty setting.</p>

</dd>
<dt id="$object-&gt;match_max($maximum_buffer_length-|-undef)-or"><a id="object--match_max-maximum_buffer_length---undef--or"></a>$object-&gt;match_max($maximum_buffer_length | undef) <i>or</i></dt>
<dd>

</dd>
<dt id="$object-&gt;max_accum($maximum_buffer_length-|-undef)"><a id="object--max_accum-maximum_buffer_length---undef"></a>$object-&gt;max_accum($maximum_buffer_length | undef)</dt>
<dd>

<p>Set the maximum accumulator size for object. This is useful if you think that the accumulator will grow out of hand during expect() calls. Since the buffer will be matched by every match_pattern it may get slow if the buffer gets too large. Returns current value if called without parameters. Not defined by default.</p>

</dd>
<dt id="$object-&gt;notransfer(0-|-1)"><a id="object--notransfer-0---1"></a>$object-&gt;notransfer(0 | 1)</dt>
<dd>

<p>If set, matched strings will not be deleted from the accumulator. Returns current value if called without parameters. False by default.</p>

</dd>
<dt id="$object-&gt;exp_pid()-or"><a id="object--exp_pid--or"></a>$object-&gt;exp_pid() <i>or</i></dt>
<dd>

</dd>
<dt id="$object-&gt;pid()"><a id="object--pid"></a>$object-&gt;pid()</dt>
<dd>

<p>Return pid of $object, if one exists. Initialized filehandles will not have pids (of course).</p>

</dd>
<dt id="$object-&gt;send_slow($delay,-@strings);"><a id="object--send_slow-delay---strings"></a>$object-&gt;send_slow($delay, @strings);</dt>
<dd>

<p>print each character from each string of @strings one at a time with $delay seconds before each character. This is handy for devices such as modems that can be annoying if you send them data too fast. After each character $object will be checked to determine whether or not it has any new data ready and if so update the accumulator for future expect() calls and print the output to STDOUT and @listen_group if log_stdout and log_group are appropriately set.</p>

</dd>
</dl>

<h2 id="Configurable-Package-Variables:"><a id="Configurable"></a><a id="Configurable-Package-Variables"></a>Configurable Package Variables:</h2>

<dl>

<dt id="$Expect::Debug"><a id="Expect::Debug"></a>$Expect::Debug</dt>
<dd>

<p>Defaults to 0. Newly created objects have a $object-&gt;debug() value of $Expect::Debug. See $object-&gt;debug();</p>

</dd>
<dt id="$Expect::Do_Soft_Close"><a id="Expect::Do_Soft_Close"></a>$Expect::Do_Soft_Close</dt>
<dd>

<p>Defaults to 0. When destroying objects, soft_close may take up to half a minute to shut everything down. From now on, only hard_close will be called, which is less polite but still gives the process a chance to terminate properly. Set this to &#39;1&#39; for old behaviour.</p>

</dd>
<dt id="$Expect::Exp_Internal"><a id="Expect::Exp_Internal"></a>$Expect::Exp_Internal</dt>
<dd>

<p>Defaults to 0. Newly created objects have a $object-&gt;exp_internal() value of $Expect::Exp_Internal. See $object-&gt;exp_internal().</p>

</dd>
<dt id="$Expect::IgnoreEintr"><a id="Expect::IgnoreEintr"></a>$Expect::IgnoreEintr</dt>
<dd>

<p>Defaults to 0. If set to 1, when waiting for new data, Expect will ignore EINTR errors and restart the select() call instead.</p>

</dd>
<dt id="$Expect::Log_Group"><a id="Expect::Log_Group"></a>$Expect::Log_Group</dt>
<dd>

<p>Defaults to 1. Newly created objects have a $object-&gt;log_group() value of $Expect::Log_Group. See $object-&gt;log_group().</p>

</dd>
<dt id="$Expect::Log_Stdout"><a id="Expect::Log_Stdout"></a>$Expect::Log_Stdout</dt>
<dd>

<p>Defaults to 1 for spawned commands, 0 for file handles attached with exp_init(). Newly created objects have a $object-&gt;log_stdout() value of $Expect::Log_Stdout. See $object-&gt;log_stdout().</p>

</dd>
<dt id="$Expect::Manual_Stty"><a id="Expect::Manual_Stty"></a>$Expect::Manual_Stty</dt>
<dd>

<p>Defaults to 0. Newly created objects have a $object-&gt;manual_stty() value of $Expect::Manual_Stty. See $object-&gt;manual_stty().</p>

</dd>
<dt id="$Expect::Multiline_Matching"><a id="Expect::Multiline_Matching"></a>$Expect::Multiline_Matching</dt>
<dd>

<p>Defaults to 1. Affects whether or not expect() uses the /m flag for doing regular expression matching. If set to 1 /m is used.</p>

<p>This makes a difference when you are trying to match ^ and $. If you have this on you can match lines in the middle of a page of output using ^ and $ instead of it matching the beginning and end of the entire expression. I think this is handy.</p>

<p>The $Expect::Multiline_Matching turns on and off Expect&#39;s multi-line matching mode. But this only has an effect if you pass in a string, and then use &#39;-re&#39; mode. If you pass in a regular expression value (via qr//), then the qr//&#39;s own flags are preserved irrespective of what it gets interpolated into. There was a bug in Perl 5.8.x where interpolating a regex without /m into a match with /m would incorrectly apply the /m to the inner regex too, but this was fixed in Perl 5.10. The correct behavior, as seen in Perl 5.10, is that if you pass in a regex (via qr//), then $Expect::Multiline_Matching has no effect. So if you pass in a regex, then you must use the qr&#39;s flags to control whether it is multiline (which by default it is not, opposite of the default behavior of Expect).</p>

</dd>
</dl>

<h1 id="CONTRIBUTIONS">CONTRIBUTIONS</h1>

<p>Lee Eakin &lt;leakin@japh.itg.ti.com&gt; has ported the kibitz script from Tcl/Expect to Perl/Expect.</p>

<p>Jeff Carr &lt;jcarr@linuxmachines.com&gt; provided a simple example of how handle terminal window resize events (transmitted via the WINCH signal) in a ssh session.</p>

<p>You can find both scripts in the examples/ subdir. Thanks to both!</p>

<p>Historical notes:</p>

<p>There are still a few lines of code dating back to the inspirational Comm.pl and Chat.pl modules without which this would not have been possible. Kudos to Eric Arnold &lt;Eric.Arnold@Sun.com&gt; and Randal &#39;Nuke your NT box with one line of perl code&#39; Schwartz&lt;merlyn@stonehenge.com&gt; for making these available to the perl public.</p>

<p>As of .98 I think all the old code is toast. No way could this have been done without it though. Special thanks to Graham Barr for helping make sense of the IO::Handle stuff as well as providing the highly recommended IO::Tty module.</p>

<h1 id="REFERENCES">REFERENCES</h1>

<p>Mark Rogaski &lt;rogaski@att.com&gt; wrote:</p>

<p>&quot;I figured that you&#39;d like to know that Expect.pm has been very useful to AT&amp;T Labs over the past couple of years (since I first talked to Austin about design decisions). We use Expect.pm for managing the switches in our network via the telnet interface, and such automation has significantly increased our reliability. So, you can honestly say that one of the largest digital networks in existence (AT&amp;T Frame Relay) uses Expect.pm quite extensively.&quot;</p>

<h1 id="FAQ-Frequently-Asked-Questions"><a id="FAQ"></a>FAQ - Frequently Asked Questions</h1>

<p>This is a growing collection of things that might help. Please send you questions that are not answered here to RGiersig@cpan.org</p>

<h2 id="What-systems-does-Expect-run-on?"><a id="What"></a><a id="What-systems-does-Expect-run-on"></a>What systems does Expect run on?</h2>

<p>Expect itself doesn&#39;t have real system dependencies, but the underlying IO::Tty needs pseudoterminals. IO::Stty uses POSIX.pm and Fcntl.pm.</p>

<p>I have used it on Solaris, Linux and AIX, others report *BSD and OSF as working. Generally, any modern POSIX Unix should do, but there are exceptions to every rule. Feedback is appreciated.</p>

<p>See <a href="https://metacpan.org/pod/IO::Tty">IO::Tty</a> for a list of verified systems.</p>

<h2 id="Can-I-use-this-module-with-ActivePerl-on-Windows?"><a id="Can"></a><a id="Can-I-use-this-module-with-ActivePerl-on-Windows"></a>Can I use this module with ActivePerl on Windows?</h2>

<p>Up to now, the answer was &#39;No&#39;, but this has changed.</p>

<p>You still cannot use ActivePerl, but if you use the Cygwin environment (http://sources.redhat.com), which brings its own perl, and have the latest IO::Tty (v0.05 or later) installed, it should work (feedback appreciated).</p>

<h2 id="The-examples-in-the-tutorial-don&#39;t-work!"><a id="The"></a><a id="The-examples-in-the-tutorial-don-t-work"></a>The examples in the tutorial don&#39;t work!</h2>

<p>The tutorial is hopelessly out of date and needs a serious overhaul. I apologize for this, I have concentrated my efforts mainly on the functionality. Volunteers welcomed.</p>

<h2 id="How-can-I-find-out-what-Expect-is-doing?"><a id="How"></a><a id="How-can-I-find-out-what-Expect-is-doing"></a>How can I find out what Expect is doing?</h2>

<p>If you set</p>

<pre><code>  $Expect::Exp_Internal = 1;</code></pre>

<p>Expect will tell you very verbosely what it is receiving and sending, what matching it is trying and what it found. You can do this on a per-command base with</p>

<pre><code>  $exp-&gt;exp_internal(1);</code></pre>

<p>You can also set</p>

<pre><code>  $Expect::Debug = 1;  # or 2, 3 for more verbose output</code></pre>

<p>or</p>

<pre><code>  $exp-&gt;debug(1);</code></pre>

<p>which gives you even more output.</p>

<h2 id="I-am-seeing-the-output-of-the-command-I-spawned.-Can-I-turn-that-off?"><a id="I"></a><a id="I-am-seeing-the-output-of-the-command-I-spawned.-Can-I-turn-that-off"></a>I am seeing the output of the command I spawned. Can I turn that off?</h2>

<p>Yes, just set</p>

<pre><code>  $Expect::Log_Stdout = 0;</code></pre>

<p>to globally disable it or</p>

<pre><code>   $exp-&gt;log_stdout(0);</code></pre>

<p>for just that command. &#39;log_user&#39; is provided as an alias so Tcl/Expect user get a DWIM experience... :-)</p>

<h2 id="No,-I-mean-that-when-I-send-some-text-to-the-spawned-process,-it-gets-echoed-back-and-I-have-to-deal-with-it-in-the-next-expect."><a id="No"></a><a id="No--I-mean-that-when-I-send-some-text-to-the-spawned-process--it-gets-echoed-back-and-I-have-to-deal-with-it-in-the-next-expect"></a>No, I mean that when I send some text to the spawned process, it gets echoed back and I have to deal with it in the next expect.</h2>

<p>This is caused by the pty, which has probably &#39;echo&#39; enabled. A solution would be to set the pty to raw mode, which in general is cleaner for communication between two programs (no more unexpected character translations). Unfortunately this would break a lot of old code that sends &quot;\r&quot; to the program instead of &quot;\n&quot; (translating this is also handled by the pty), so I won&#39;t add this to Expect just like that. But feel free to experiment with <code>$exp-&gt;raw_pty(1)</code>.</p>

<h2 id="How-do-I-send-control-characters-to-a-process?"><a id="How1"></a><a id="How-do-I-send-control-characters-to-a-process"></a>How do I send control characters to a process?</h2>

<p>A: You can send any characters to a process with the print command. To represent a control character in Perl, use \c followed by the letter. For example, control-G can be represented with &quot;\cG&quot; . Note that this will not work if you single-quote your string. So, to send control-C to a process in $exp, do:</p>

<pre><code>  print $exp &quot;\cC&quot;;</code></pre>

<p>Or, if you prefer:</p>

<pre><code>  $exp-&gt;send(&quot;\cC&quot;);</code></pre>

<p>The ability to include control characters in a string like this is provided by Perl, not by Expect.pm . Trying to learn Expect.pm without a thorough grounding in Perl can be very daunting. We suggest you look into some of the excellent Perl learning material, such as the books _Programming Perl_ and _Learning Perl_ by O&#39;Reilly, as well as the extensive online Perl documentation available through the perldoc command.</p>

<h2 id="My-script-fails-from-time-to-time-without-any-obvious-reason.-It-seems-that-I-am-sometimes-loosing-output-from-the-spawned-program."><a id="My"></a><a id="My-script-fails-from-time-to-time-without-any-obvious-reason.-It-seems-that-I-am-sometimes-loosing-output-from-the-spawned-program"></a>My script fails from time to time without any obvious reason. It seems that I am sometimes loosing output from the spawned program.</h2>

<p>You could be exiting too fast without giving the spawned program enough time to finish. Try adding $exp-&gt;soft_close() to terminate the program gracefully or do an expect() for &#39;eof&#39;.</p>

<p>Alternatively, try adding a &#39;sleep 1&#39; after you spawn() the program. It could be that pty creation on your system is just slow (but this is rather improbable if you are using the latest IO-Tty).</p>

<h2 id="I-want-to-automate-password-entry-for-su/ssh/scp/rsh/..."><a id="I1"></a><a id="I-want-to-automate-password-entry-for-su-ssh-scp-rsh"></a>I want to automate password entry for su/ssh/scp/rsh/...</h2>

<p>You shouldn&#39;t use Expect for this. Putting passwords, especially root passwords, into scripts in clear text can mean severe security problems. I strongly recommend using other means. For &#39;su&#39;, consider switching to &#39;sudo&#39;, which gives you root access on a per-command and per-user basis without the need to enter passwords. &#39;ssh&#39;/&#39;scp&#39; can be set up with RSA authentication without passwords. &#39;rsh&#39; can use the .rhost mechanism, but I&#39;d strongly suggest to switch to &#39;ssh&#39;; to mention &#39;rsh&#39; and &#39;security&#39; in the same sentence makes an oxymoron.</p>

<p>It will work for &#39;telnet&#39;, though, and there are valid uses for it, but you still might want to consider using &#39;ssh&#39;, as keeping cleartext passwords around is very insecure.</p>

<h2 id="I-want-to-use-Expect-to-automate-[anything-with-a-buzzword]..."><a id="I2"></a><a id="I-want-to-use-Expect-to-automate--anything-with-a-buzzword"></a>I want to use Expect to automate [anything with a buzzword]...</h2>

<p>Are you sure there is no other, easier way? As a rule of thumb, Expect is useful for automating things that expect to talk to a human, where no formal standard applies. For other tasks that do follow a well-defined protocol, there are often better-suited modules that already can handle those protocols. Don&#39;t try to do HTTP requests by spawning telnet to port 80, use LWP instead. To automate FTP, take a look at <a href="https://metacpan.org/pod/Net::FTP">Net::FTP</a> or <code>ncftp</code> (http://www.ncftp.org). You don&#39;t use a screwdriver to hammer in your nails either, or do you?</p>

<h2 id="Is-it-possible-to-use-threads-with-Expect?"><a id="Is"></a><a id="Is-it-possible-to-use-threads-with-Expect"></a>Is it possible to use threads with Expect?</h2>

<p>Basically yes, with one restriction: you must spawn() your programs in the main thread and then pass the Expect objects to the handling threads. The reason is that spawn() uses fork(), and <a href="https://metacpan.org/pod/perlthrtut">perlthrtut</a>:</p>

<pre><code>  &quot;Thinking of mixing fork() and threads?  Please lie down and wait until the feeling passes.&quot;</code></pre>

<h2 id="I-want-to-log-the-whole-session-to-a-file."><a id="I3"></a><a id="I-want-to-log-the-whole-session-to-a-file"></a>I want to log the whole session to a file.</h2>

<p>Use</p>

<pre><code>  $exp-&gt;log_file(&quot;filename&quot;);</code></pre>

<p>or</p>

<pre><code>  $exp-&gt;log_file($filehandle);</code></pre>

<p>or even</p>

<pre><code>  $exp-&gt;log_file(\&amp;log_procedure);</code></pre>

<p>for maximum flexibility.</p>

<p>Note that the logfile is appended to by default, but you can specify an optional mode &quot;w&quot; to truncate the logfile:</p>

<pre><code>  $exp-&gt;log_file(&quot;filename&quot;, &quot;w&quot;);</code></pre>

<p>To stop logging, just call it with a false argument:</p>

<pre><code>  $exp-&gt;log_file(undef);</code></pre>

<h2 id="How-can-I-turn-off-multi-line-matching-for-my-regexps?"><a id="How2"></a><a id="How-can-I-turn-off-multi-line-matching-for-my-regexps"></a>How can I turn off multi-line matching for my regexps?</h2>

<p>To globally unset multi-line matching for all regexps:</p>

<pre><code>  $Expect::Multiline_Matching = 0;</code></pre>

<p>You can do that on a per-regexp basis by stating <code>(?-m)</code> inside the regexp (you need perl5.00503 or later for that).</p>

<h2 id="How-can-I-expect-on-multiple-spawned-commands?"><a id="How3"></a><a id="How-can-I-expect-on-multiple-spawned-commands"></a>How can I expect on multiple spawned commands?</h2>

<p>You can use the <b>-i</b> parameter to specify a single object or a list of Expect objects. All following patterns will be evaluated against that list.</p>

<p>You can specify <b>-i</b> multiple times to create groups of objects and patterns to match against within the same expect statement.</p>

<p>This works just like in Tcl/Expect.</p>

<p>See the source example below.</p>

<h2 id="I-seem-to-have-problems-with-ptys!"><a id="I4"></a><a id="I-seem-to-have-problems-with-ptys"></a>I seem to have problems with ptys!</h2>

<p>Well, pty handling is really a black magic, as it is extremely system dependent. I have extensively revised IO-Tty, so these problems should be gone.</p>

<p>If your system is listed in the &quot;verified&quot; list of IO::Tty, you probably have some non-standard setup, e.g. you compiled your Linux-kernel yourself and disabled ptys. Please ask your friendly sysadmin for help.</p>

<p>If your system is not listed, unpack the latest version of IO::Tty, do a &#39;perl Makefile.PL; make; make test; uname <code>-a</code>&#39; and send me the results and I&#39;ll see what I can deduce from that.</p>

<h2 id="I-just-want-to-read-the-output-of-a-process-without-expect()ing-anything.-How-can-I-do-this?"><a id="I5"></a><a id="I-just-want-to-read-the-output-of-a-process-without-expect-ing-anything.-How-can-I-do-this"></a>I just want to read the output of a process without expect()ing anything. How can I do this?</h2>

<p>[ Are you sure you need Expect for this? How about qx() or open(&quot;prog|&quot;)? ]</p>

<p>By using expect without any patterns to match.</p>

<pre><code>  $process-&gt;expect(undef); # Forever until EOF
  $process-&gt;expect($timeout); # For a few seconds
  $process-&gt;expect(0); # Is there anything ready on the handle now?</code></pre>

<h2 id="Ok,-so-now-how-do-I-get-what-was-read-on-the-handle?"><a id="Ok"></a><a id="Ok--so-now-how-do-I-get-what-was-read-on-the-handle"></a>Ok, so now how do I get what was read on the handle?</h2>

<pre><code>  $read = $process-&gt;before();</code></pre>

<h2 id="Where&#39;s-IO::Pty?"><a id="Where"></a><a id="Where-s-IO::Pty"></a>Where&#39;s IO::Pty?</h2>

<p>Find it on CPAN as IO-Tty, which provides both.</p>

<h2 id="How-come-when-I-automate-the-passwd-program-to-change-passwords-for-me-passwd-dies-before-changing-the-password-sometimes/every-time?"><a id="How4"></a><a id="How-come-when-I-automate-the-passwd-program-to-change-passwords-for-me-passwd-dies-before-changing-the-password-sometimes-every-time"></a>How come when I automate the passwd program to change passwords for me passwd dies before changing the password sometimes/every time?</h2>

<p>What&#39;s happening is you are closing the handle before passwd exits. When you close the handle to a process, it is sent a signal (SIGPIPE?) telling it that STDOUT has gone away. The default behavior for processes is to die in this circumstance. Two ways you can make this not happen are:</p>

<pre><code>  $process-&gt;soft_close();</code></pre>

<p>This will wait 15 seconds for a process to come up with an EOF by itself before killing it.</p>

<pre><code>  $process-&gt;expect(undef);</code></pre>

<p>This will wait forever for the process to match an empty set of patterns. It will return when the process hits an EOF.</p>

<p>As a rule, you should always expect() the result of your transaction before you continue with processing.</p>

<h2 id="How-come-when-I-try-to-make-a-logfile-with-log_file()-or-set_group()-it-doesn&#39;t-print-anything-after-the-last-time-I-run-expect()?"><a id="How5"></a><a id="How-come-when-I-try-to-make-a-logfile-with-log_file--or-set_group--it-doesn-t-print-anything-after-the-last-time-I-run-expect"></a>How come when I try to make a logfile with log_file() or set_group() it doesn&#39;t print anything after the last time I run expect()?</h2>

<p>Output is only printed to the logfile/group when Expect reads from the process, during expect(), send_slow() and interconnect(). One way you can force this is to make use of</p>

<pre><code>  $process-&gt;expect(undef);</code></pre>

<p>and</p>

<pre><code>  $process-&gt;expect(0);</code></pre>

<p>which will make expect() run with an empty pattern set forever or just for an instant to capture the output of $process. The output is available in the accumulator, so you can grab it using $process-&gt;before().</p>

<h2 id="I-seem-to-have-problems-with-terminal-settings,-double-echoing,-etc."><a id="I6"></a><a id="I-seem-to-have-problems-with-terminal-settings--double-echoing--etc"></a>I seem to have problems with terminal settings, double echoing, etc.</h2>

<p>Tty settings are a major pain to keep track of. If you find unexpected behavior such as double-echoing or a frozen session, doublecheck the documentation for default settings. When in doubt, handle them yourself using $exp-&gt;stty() and manual_stty() functions. As of .98 you shouldn&#39;t have to worry about stty settings getting fouled unless you use interconnect or intentionally change them (like doing -echo to get a password).</p>

<p>If you foul up your terminal&#39;s tty settings, kill any hung processes and enter &#39;stty sane&#39; at a shell prompt. This should make your terminal manageable again.</p>

<p>Note that IO::Tty returns ptys with your systems default setting regarding echoing, CRLF translation etc. and Expect does not change them. I have considered setting the ptys to &#39;raw&#39; without any translation whatsoever, but this would break a lot of existing things, as &#39;\r&#39; translation would not work anymore. On the other hand, a raw pty works much like a pipe and is more WYGIWYE (what you get is what you expect), so I suggest you set it to &#39;raw&#39; by yourself:</p>

<pre><code>  $exp = Expect-&gt;new;
  $exp-&gt;raw_pty(1);
  $exp-&gt;spawn(...);</code></pre>

<p>To disable echo:</p>

<pre><code>  $exp-&gt;slave-&gt;stty(qw(-echo));</code></pre>

<h2 id="I&#39;m-spawning-a-telnet/ssh-session-and-then-let-the-user-interact-with-it.-But-screen-oriented-applications-on-the-other-side-don&#39;t-work-properly."><a id="I7"></a><a id="I-m-spawning-a-telnet-ssh-session-and-then-let-the-user-interact-with-it.-But-screen-oriented-applications-on-the-other-side-don-t-work-properly"></a>I&#39;m spawning a telnet/ssh session and then let the user interact with it. But screen-oriented applications on the other side don&#39;t work properly.</h2>

<p>You have to set the terminal screen size for that. Luckily, IO::Pty already has a method for that, so modify your code to look like this:</p>

<pre><code>  my $exp = Expect-&gt;new;
  $exp-&gt;slave-&gt;clone_winsize_from(\*STDIN);
  $exp-&gt;spawn(&quot;telnet somehost);</code></pre>

<p>Also, some applications need the TERM shell variable set so they know how to move the cursor across the screen. When logging in, the remote shell sends a query (Ctrl-Z I think) and expects the terminal to answer with a string, e.g. &#39;xterm&#39;. If you really want to go that way (be aware, madness lies at its end), you can handle that and send back the value in $ENV{TERM}. This is only a hand-waving explanation, please figure out the details by yourself.</p>

<h2 id="I-set-the-terminal-size-as-explained-above,-but-if-I-resize-the-window,-the-application-does-not-notice-this."><a id="I8"></a><a id="I-set-the-terminal-size-as-explained-above--but-if-I-resize-the-window--the-application-does-not-notice-this"></a>I set the terminal size as explained above, but if I resize the window, the application does not notice this.</h2>

<p>You have to catch the signal WINCH (&quot;window size changed&quot;), change the terminal size and propagate the signal to the spawned application:</p>

<pre><code>  my $exp = Expect-&gt;new;
  $exp-&gt;slave-&gt;clone_winsize_from(\*STDIN);
  $exp-&gt;spawn(&quot;ssh somehost);
  $SIG{WINCH} = \&amp;winch;

  sub winch {
    $exp-&gt;slave-&gt;clone_winsize_from(\*STDIN);
    kill WINCH =&gt; $exp-&gt;pid if $exp-&gt;pid;
    $SIG{WINCH} = \&amp;winch;
  }

  $exp-&gt;interact();</code></pre>

<p>There is an example file ssh.pl in the examples/ subdir that shows how this works with ssh. Please note that I do strongly object against using Expect to automate ssh login, as there are better way to do that (see <a href="https://metacpan.org/pod/ssh-keygen">ssh-keygen</a>).</p>

<h2 id="I-noticed-that-the-test-uses-a-string-that-resembles,-but-not-exactly-matches,-a-well-known-sentence-that-contains-every-character.-What-does-that-mean?"><a id="I9"></a><a id="I-noticed-that-the-test-uses-a-string-that-resembles--but-not-exactly-matches--a-well-known-sentence-that-contains-every-character.-What-does-that-mean"></a>I noticed that the test uses a string that resembles, but not exactly matches, a well-known sentence that contains every character. What does that mean?</h2>

<p>That means you are anal-retentive. :-) [Gotcha there!]</p>

<h2 id="I-get-a-&quot;Could-not-assign-a-pty&quot;-error-when-running-as-a-non-root-user-on-an-IRIX-box?"><a id="I10"></a><a id="I-get-a--Could-not-assign-a-pty--error-when-running-as-a-non-root-user-on-an-IRIX-box"></a>I get a &quot;Could not assign a pty&quot; error when running as a non-root user on an IRIX box?</h2>

<p>The OS may not be configured to grant additional pty&#39;s (pseudo terminals) to non-root users. /usr/sbin/mkpts should be 4755, not 700 for this to work. I don&#39;t know about security implications if you do this.</p>

<h2 id="How-come-I-don&#39;t-notice-when-the-spawned-process-closes-its-stdin/out/err??"><a id="How6"></a><a id="How-come-I-don-t-notice-when-the-spawned-process-closes-its-stdin-out-err"></a>How come I don&#39;t notice when the spawned process closes its stdin/out/err??</h2>

<p>You are probably on one of the systems where the master doesn&#39;t get an EOF when the slave closes stdin/out/err.</p>

<p>One possible solution is when you spawn a process, follow it with a unique string that would indicate the process is finished.</p>

<pre><code>  $process = Expect-&gt;spawn(&#39;telnet somehost; echo ____END____&#39;);</code></pre>

<p>And then $process-&gt;expect($timeout,&#39;____END____&#39;,&#39;other&#39;,&#39;patterns&#39;);</p>

<h1 id="Source-Examples"><a id="Source"></a>Source Examples</h1>

<h2 id="How-to-automate-login"><a id="How7"></a>How to automate login</h2>

<pre><code>  my $telnet = Net::Telnet-&gt;new(&quot;remotehost&quot;) # see Net::Telnet
    or die &quot;Cannot telnet to remotehost: $!\n&quot;;;
  my $exp = Expect-&gt;exp_init($telnet);

  # deprecated use of spawned telnet command
  # my $exp = Expect-&gt;spawn(&quot;telnet localhost&quot;)
  #   or die &quot;Cannot spawn telnet: $!\n&quot;;;

  my $spawn_ok;
  $exp-&gt;expect($timeout,
           [
        qr&#39;login: $&#39;,
        sub {
                  $spawn_ok = 1;
          my $fh = shift;
          $fh-&gt;send(&quot;$username\n&quot;);
                  exp_continue;
        }
           ],
           [
        &#39;Password: $&#39;,
        sub {
          my $fh = shift;
          print $fh &quot;$password\n&quot;;
                  exp_continue;
        }
           ],
           [
        eof =&gt;
        sub {
                  if ($spawn_ok) {
            die &quot;ERROR: premature EOF in login.\n&quot;;
                  } else {
            die &quot;ERROR: could not spawn telnet.\n&quot;;
                  }
        }
           ],
           [
        timeout =&gt;
        sub {
          die &quot;No login.\n&quot;;
        }
           ],
           &#39;-re&#39;, qr&#39;[#&gt;:] $&#39;, #&#39; wait for shell prompt, then exit expect
          );</code></pre>

<h2 id="How-to-expect-on-multiple-spawned-commands"><a id="How8"></a>How to expect on multiple spawned commands</h2>

<pre><code>  foreach my $cmd (@list_of_commands) {
    push @commands, Expect-&gt;spawn($cmd);
  }

  expect($timeout,
     &#39;-i&#39;, \@commands,
     [
      qr&quot;pattern&quot;,        # find this pattern in output of all commands
      sub {
        my $obj = shift;    # object that matched
        print $obj &quot;something\n&quot;;
        exp_continue;    # we don&#39;t want to terminate the expect call
      }
     ],
     &#39;-i&#39;, $some_other_command,
     [
      &quot;some other pattern&quot;,
      sub {
        my ($obj, $parmref) = @_;
        # ...

        # now we exit the expect command
      },
      \$parm
     ],
    );</code></pre>

<h2 id="How-to-propagate-terminal-sizes"><a id="How9"></a>How to propagate terminal sizes</h2>

<pre><code>  my $exp = Expect-&gt;new;
  $exp-&gt;slave-&gt;clone_winsize_from(\*STDIN);
  $exp-&gt;spawn(&quot;ssh somehost);
  $SIG{WINCH} = \&amp;winch;

  sub winch {
    $exp-&gt;slave-&gt;clone_winsize_from(\*STDIN);
    kill WINCH =&gt; $exp-&gt;pid if $exp-&gt;pid;
    $SIG{WINCH} = \&amp;winch;
  }

  $exp-&gt;interact();</code></pre>

<h1 id="HOMEPAGE">HOMEPAGE</h1>

<p><a href="http://sourceforge.net/projects/expectperl/">http://sourceforge.net/projects/expectperl/</a> though the source code is now in GitHub: <a href="https://github.com/jacoby/expect.pm">https://github.com/jacoby/expect.pm</a></p>

<h1 id="MAILING-LISTS"><a id="MAILING"></a>MAILING LISTS</h1>

<p>There are two mailing lists available, expectperl-announce and expectperl-discuss, at</p>

<pre><code>  http://lists.sourceforge.net/lists/listinfo/expectperl-announce</code></pre>

<p>and</p>

<pre><code>  http://lists.sourceforge.net/lists/listinfo/expectperl-discuss</code></pre>

<h1 id="BUG-TRACKING"><a id="BUG"></a>BUG TRACKING</h1>

<p>You can use the CPAN Request Tracker http://rt.cpan.org/ and submit new bugs under</p>

<pre><code>  http://rt.cpan.org/Ticket/Create.html?Queue=Expect</code></pre>

<h1 id="AUTHORS">AUTHORS</h1>

<p>(c) 1997 Austin Schutz &lt;<i>ASchutz@users.sourceforge.net</i>&gt; (retired)</p>

<p>expect() interface &amp; functionality enhancements (c) 1999-2006 Roland Giersig.</p>

<p>This module is now maintained by Dave Jacoby &lt;<i>jacoby@cpan.org</i>&gt;</p>

<h1 id="LICENSE">LICENSE</h1>

<p>This module can be used under the same terms as Perl.</p>

<h1 id="DISCLAIMER">DISCLAIMER</h1>

<p>THIS SOFTWARE IS PROVIDED ``AS IS&#39;&#39; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p>

<p>In other words: Use at your own risk. Provided as is. Your mileage may vary. Read the source, Luke!</p>

<p>And finally, just to be sure:</p>

<p>Any Use of This Product, in Any Manner Whatsoever, Will Increase the Amount of Disorder in the Universe. Although No Liability Is Implied Herein, the Consumer Is Warned That This Process Will Ultimately Lead to the Heat Death of the Universe.</p></div>

<div id="metacpan_install-instructions-dialog" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Module Install Instructions</h4>
      </div>
      <div class="modal-body">
        <p>To install Expect, copy and paste the appropriate command in to your terminal.</p>
        <p><a href="https://metacpan.org/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p>
        <pre><code>cpanm Expect</code></pre>
        <p><a href="https://metacpan.org/pod/CPAN">CPAN shell</a></p>
        <pre><code>perl -MCPAN -e shell
install Expect</code></pre>
        <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p>
      </div>
      <div class="modal-footer">
        <a href="Expect.html#" data-dismiss="modal" class="btn">Close</a>
      </div>
    </div>
  </div>
</div>
          </main>
          <div class="content-pagination">
          </div>
        </div>
        <footer class="footer">
          <div class="footer-container">
            <div class="footer-social">
              <div class="footer-link footer-logo">
                <a href="https://metacpan.org/">
                  <img src="https://metacpan.org/static/images/metacpan-logo.svg" alt="MetaCPAN" />
                </a>
              </div>
              <a class="footer-social-link" href="https://github.com/metacpan">
                <i class="fab fa-github-square"></i>
              </a>
              <a class="footer-social-link" href="https://fosstodon.org/@metacpan">
                <i class="fab fa-mastodon"></i>
              </a>
            </div>
            <div class="footer-links">
              <div class="footer-link">
                  <a href="https://metacpan.org/about">About</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/sponsors">Sponsor</a>
              </div>
              <div class="footer-link">
                  <a href="https://grep.metacpan.org">grep::cpan</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/recent">Recent</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/faq">FAQ</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/tools">Tools</a>
              </div>
              <div class="footer-link">
                  <a href="https://fastapi.metacpan.org/">API</a>
              </div>
              <div class="footer-link">
                  <a href="https://www.perl.org/">Perl.org</a>
              </div>
            </div>
            <div class="footer-sponsors">
              <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener">
                <img class="footer-sponsor-bytemark" src="https://metacpan.org/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener">
                <img class="footer-sponsor-liquidweb" src="https://metacpan.org/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener">
                <img class="footer-sponsor-deriv" src="https://metacpan.org/static/images/sponsors/deriv.svg" alt="Deriv logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener">
                <img class="footer-sponsor-geocode" src="https://metacpan.org/static/images/sponsors/geocodelogo.svg" alt="Geocode logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener">
                <img class="footer-sponsor-fastly" src="https://metacpan.org/static/images/sponsors/fastly_logo.svg" alt="Fastly logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener">
                <img class="footer-sponsor-opencage" src="https://metacpan.org/static/images/sponsors/open-cage.svg" alt="OpenCage logo">
              </a>
            </div>
          </div>
        </footer>
        <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Keyboard Shortcuts</h4>
              </div>
              <div class="modal-body row">
<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Global</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>s</kbd>
        </td>
        <td>Focus search bar</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>?</kbd>
        </td>
        <td>Bring up this help dialog</td>
      </tr>
    </tbody>
  </table>

  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>GitHub</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>p</kbd>
        </td>
        <td>Go to pull requests</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>go to github issues (only if github is preferred repository)</td>
      </tr>
    </tbody>
  </table>
</div>

<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>POD</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>a</kbd>
        </td>
        <td>Go to author</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>c</kbd>
        </td>
        <td>Go to changes</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>Go to issues</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>d</kbd>
        </td>
        <td>Go to dist</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>r</kbd>
        </td>
        <td>Go to repository/SCM</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>s</kbd>
        </td>
        <td>Go to source</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>b</kbd>
        </td>
        <td>Go to file browse</td>
      </tr>

    </tbody>
  </table>
</div>

<div class="col-md-12">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Search terms</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><em>module:</em> (e.g. <a href="https://metacpan.org/search?q=module%3APlugin">module:Plugin</a>)</td>
      </tr>
      <tr>
        <td><em>distribution:</em> (e.g. <a href="https://metacpan.org/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td>
      </tr>
      <tr>
        <td><em>author:</em> (e.g. <a href="https://metacpan.org/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td>
      </tr>
      <tr>
        <td><em>version:</em> (e.g. <a href="https://metacpan.org/search?q=version%3A1.00">version:1.00</a>)</td>
      </tr>
    </tbody>
  </table>
</div>
              </div>
              <div class="modal-footer"></div>
            </div>
          </div>
        </div>
    </body>
</html>
